<include file="_head,_download_app"/>
<if condition="empty($_GET['token'])">

    <section class="app_content">
        <h1>{$act_title}</h1>
        <div class="time">活动时间：{$start_time}-{$end_time}</div>
        <div class="cont">
            <p><img src="{$act_pic|default='__PUBLIC__/H5asset/images/img02.jpg'}"/></p>
            <p>{$act_content}</p>
        </div>
    </section>

    <else/>

    <section class="app_content">
        <h1>{$act_title}</h1>
        <div class="img">
            <img src="{$act_pic|default='__PUBLIC__/H5asset/images/img02.jpg'}"/>

            <span class="{$is_add_favarate ?'already':''}" id="favorite" data-url="{$add_favorite_url}"></span>
            <p>活动时间：{$start_time}-{$end_time}</p>
        </div>
        <div class="cont">
            <p>{$act_content}</p>
        </div>
        <if condition="$is_expire GT 0">

                        <div class="btn">
                            <a class="already">活动已过期</a>
                        </div>

            <else/>
                        <div class="btn">
                            <a class="{$is_join ? 'already' : ''}" data-url="{$join_act_url}" id="join" href="#">{$is_join ? '取消参加'
                                : '我要参加'}</a>
                        </div>

        </if>

    </section>
</if>


<script>
    var act_id = "{$_GET['id']}";//活动id
    var token = "{$_GET['token']}";//token

    $(function () {
        //参加活动
        function join(actId, typeId) {
            $.ajax({
                url: '/ApiWF/Activity/getActivity',
                type: 'POST',
                dataType: 'json',
                data: {act_id: actId, type: typeId, token: token},
                success: function (data) {

                }
            })
        }

        $('#join').on('click', function () {
            event.preventDefault();
            if ($(this).hasClass('already')) {
                $(this).removeClass('already').text('我要参加');
                join(act_id, 2);//取消
            } else {
                $(this).addClass('already').text('取消参加');
                join(act_id, 1)//参加
            }
        })
        //添加收藏
        function favorite(actId, typeId) {
            $.ajax({
                url: '/ApiWF/Activity/getFavor',
                type: 'POST',
                data: {act_id: actId, type: typeId, token: token},
                success: function (data) {

                }
            })
        }

        $('#favorite').on('click', function () {
            event.preventDefault();

            if ($(this).hasClass('already')) {
                $(this).removeClass('already');
                favorite(act_id, 2);//取消
            } else {
                $(this).addClass('already');
                favorite(act_id, 1);//收藏
            }
        })
    })

</script>

</body>
</html>
